import { Component } from 'react';
import './Head.less';
import logo from './../../images/logo.png'
import  Form,{SearchFormField}  from 'uxcore-form';
import Message from 'uxcore-message';
import {  apiUrlPrefixProd } from './../../app/variables';
import  StorageUtils from './../../app/storage'

export default class Head extends Component {

  constructor(props) {
    super(props);
  }


  search(obj) {

    if (obj.split(',').length === 2) {

      let lx = obj.split(',')[1];
      let key = obj.split(',')[0];
      let url;

      if (lx === '03') {
        url = `/grxx/${key}`;
      } else if (lx === '02') {
        url = `/xytx/${key}`;
      } else if (lx === '01') {
        url = `/xmmx/${key}`;
        this.props.handleGcTitleClick(key);
      }
      this.context.router.push(url);
    } else {
      this.context.router.push('/search');
    }

  }

  render() {
    let me = this;
    let searchOptions = {
      jsxname: "search",
      dataType: "json",
      placeholder: "搜索数据",
      jsxfetchUrl: apiUrlPrefixProd + "sskj/search/jsxdata",
      onSelect: (value, option)=> {
        me.search(value);
      },
      afterFetch: (obj) => {
        Message['clear']('clear', 5);
        return obj.data;
      },
      allowClear: true,
      notFoundContent: '未查询到数据',
      onIconClick: (e) => {
        me.search(me.refs.form.getValues().values.search.main);
      },
      tidy: true,
      beforeFetch: (obj)=> {
        /*Message['clear']('clear', 5);
        if (obj.q) {
          Message['loading']('请等待...', 15);
        }*/
        return {
          name: obj.q,
          Authorization: StorageUtils.getToken()
        }
      },
    };

    return (
      <div className="kuma-row mod-head">
        <div className="col-md-20">
          <div className="kuma-row" style={{marginTop:'17px',marginLeft:"650px",marginRight:'20px'}}>
            <div className="title-div">
              <h2 className="title">{this.props.title}</h2>
            </div>
          </div>
          <div className="kuma-row search_div">
            <Form ref="form">
              <SearchFormField {...searchOptions} style={{width:700}}/>
            </Form>
          </div>
        </div>
        <div className="col-md-4">
          <div className="kuma-row" style={{textAlign:"right",marginRight:'70px',marginTop:'17px'}}>
            <iframe allowtransparency="true" frameborder="0" width="255" height="98" scrolling="no"
                    src="//tianqi.2345.com/plugin/widget/index.htm?s=1&z=1&t=1&v=0&d=1&bd=0&k=&f=ffffff&q=1&e=1&a=0&c=57461&w=255&h=98&align=left"></iframe>

          </div>
        </div>
      </div>
    );
  }
}
Head.contextTypes = {
  router: React.PropTypes.isRequired
};

